package com.forhappy.light3ds8.shareprefrence;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.text.TextUtils;
import android.util.Pair;

public class Config {
	public static final String CONFIG_FILE_NAME = "config";
	public static final String ITEM_USERNAME = "userName";
	public static final String ITEM_PASSWORD = "password";

	public static final String DEFAULT_USERNAME = "public";
	public static final String DEFAULT_PASSWORD = "public";

	public static final String ITEM_NO_NEED_SEE_OTHERS = "noNeedSeeOthers";
    public static final void setUserNamePassword(Context context, String userName, String password){
		SharedPreferences sf = context.getSharedPreferences(CONFIG_FILE_NAME, Activity.MODE_PRIVATE);
		Editor ed =  sf.edit();
		ed.putString(ITEM_USERNAME, userName);
		ed.putString(ITEM_PASSWORD, password);
		ed.commit();
	}

    public static Pair<String, String>getUserNamePassword(Context context){
    	SharedPreferences sf = context.getSharedPreferences(CONFIG_FILE_NAME, Activity.MODE_PRIVATE);
    	String userName = sf.getString(ITEM_USERNAME, DEFAULT_USERNAME);
    	if(TextUtils.isEmpty(userName)){
    		userName = DEFAULT_USERNAME;
    	}
    	String userPassword = sf.getString(ITEM_PASSWORD, DEFAULT_PASSWORD);
    	if(TextUtils.isEmpty(userPassword)){
    		userPassword = DEFAULT_PASSWORD;
    	}
    	Pair<String, String> userNamePassword = new Pair<String, String>(userName, userPassword);
    	return userNamePassword;
    }


    public static final void setNoNeedSeeOthers(Context context, boolean value){
		SharedPreferences sf = context.getSharedPreferences(CONFIG_FILE_NAME, Activity.MODE_PRIVATE);
		Editor ed =  sf.edit();
		ed.putBoolean(ITEM_NO_NEED_SEE_OTHERS, value);
		ed.commit();
    }
    public static final boolean getNoNeedSeeOthers(Context context){
    	SharedPreferences sf = context.getSharedPreferences(CONFIG_FILE_NAME, Activity.MODE_PRIVATE);
    	return sf.getBoolean(ITEM_NO_NEED_SEE_OTHERS, false);
    }
}
